package com.cm.caseManagement.controller;
import com.cm.caseManagement.annotation.Log;
import com.cm.caseManagement.core.controller.BaseController;
import com.cm.caseManagement.core.domain.AjaxResult;
import com.cm.caseManagement.core.page.TableDataInfo;
import com.cm.caseManagement.pojo.entity.CmSysAttachment;
import com.cm.caseManagement.pojo.enums.BusinessType;
import com.cm.caseManagement.service.ICmSysAttachmentService;
import com.cm.caseManagement.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 附件Controller
 *
 * @author ruoyi
 * @date 2025-10-05
 */
@RestController
@RequestMapping("/caseManagement/attachment")
public class CmSysAttachmentController extends BaseController
{
    @Autowired
    private ICmSysAttachmentService cmSysAttachmentService;

    /**
     * 查询附件列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmSysAttachment cmSysAttachment)
    {
        startPage();
        List<CmSysAttachment> list = cmSysAttachmentService.selectCmSysAttachmentList(cmSysAttachment);
        return getDataTable(list);
    }

    /**
     * 导出附件列表
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:export')")
    @Log(title = "附件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmSysAttachment cmSysAttachment)
    {
        List<CmSysAttachment> list = cmSysAttachmentService.selectCmSysAttachmentList(cmSysAttachment);
        ExcelUtil<CmSysAttachment> util = new ExcelUtil<CmSysAttachment>(CmSysAttachment.class);
        util.exportExcel(response, list, "附件数据");
    }

    /**
     * 获取附件详细信息
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmSysAttachmentService.selectCmSysAttachmentById(id));
    }

    /**
     * 新增附件
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:add')")
    @Log(title = "附件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmSysAttachment cmSysAttachment)
    {
        return toAjax(cmSysAttachmentService.insertCmSysAttachment(cmSysAttachment));
    }

    /**
     * 修改附件
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:edit')")
    @Log(title = "附件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmSysAttachment cmSysAttachment)
    {
        return toAjax(cmSysAttachmentService.updateCmSysAttachment(cmSysAttachment));
    }

    /**
     * 删除附件
     */
    @PreAuthorize("@ss.hasPermi('caseManagement:attachment:remove')")
    @Log(title = "附件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmSysAttachmentService.deleteCmSysAttachmentByIds(ids));
    }
}
